import java.util.Calendar;
import java.util.GregorianCalendar;

import play.test.UnitTest;
import play.test.*;
import org.junit.*;
import models.Day;
import models.DayTask;
import models.Event;
import models.EventType;
import models.Task;
import models.User;


public class C4Story1 extends UnitTest{

	@Test
	public void addeffort(){
		User Salma=new User("salma", "mohammed", "hamed", "salma", "123", "salma7amed@gmail.com",
    			"0101420501","84 bla","Cairo","Egypt","").save();
		Task task = new Task("Task 1", "High", null, null, null, Salma).save();
		task.initialEffortEstimation=20;
		EventType et2 = new EventType("Sprint").save();
		Event defEvent = new Event("default", et2);
		defEvent.tasks.add(task);
		defEvent.save();
		double effort = 18;
		Calendar c2 = new GregorianCalendar();
    	c2.set(2010,Calendar.JULY, 12);
		Day x=new Day(c2 ).save();
		int count = task.dayTasks.size();
		double dideffort=task.initialEffortEstimation;
		for(int i=0;i<task.dayTasks.size();i++)
		dideffort=dideffort-task.dayTasks.get(i).actualEffort ;
		dideffort=dideffort-effort;
		DayTask dayTask = new DayTask(dideffort,task,x).save() ;
		task.dayTasks.add(dayTask);
		task.save();		
		assertTrue(task.dayTasks.get(0).actualEffort==dideffort);
		
	}
	
	@Test
	public void editeffot(){
		
		User Salma=new User("salma", "mohammed", "hamed", "salma", "123", "salma7amed@gmail.com",
    			"0101420501","84 bla","Cairo","Egypt","").save();
		Task task = new Task("Task 1", "High", null, null, null, Salma).save();
		task.initialEffortEstimation=20;
		EventType et2 = new EventType("Sprint").save();
		Event defEvent = new Event("default", et2);
		defEvent.tasks.add(task);
		defEvent.save();
		double effort = 18;
		Calendar c2 = new GregorianCalendar();
    	c2.set(2010,Calendar.JULY, 12);
		Day x=new Day(c2 ).save();
		int count = task.dayTasks.size();
		double dideffort=task.initialEffortEstimation;
		for(int i=0;i<task.dayTasks.size();i++)
		dideffort=dideffort-task.dayTasks.get(i).actualEffort ;
		dideffort=dideffort-effort;
		DayTask dayTask = new DayTask(dideffort,task,x).save() ;
		task.dayTasks.add(dayTask);
		task.save();		
		assertTrue(task.dayTasks.get(0).actualEffort==dideffort);
		double newValue=12;
		dideffort=task.initialEffortEstimation;
		for(int i=0;i<task.dayTasks.size();i++)
		dideffort=dideffort-task.dayTasks.get(i).actualEffort ;
		dideffort=dideffort-effort;
		dayTask.actualEffort=dideffort;
		dayTask.save();
		assertTrue(task.dayTasks.get(0).actualEffort==dideffort);
	}
	
}
